public class Draw {
    private int height;

    // 构造方法，初始化高度
    public Draw(int height) {
        if (height <= 3) {
            throw new IllegalArgumentException("高度必须至少超过3行");
        }
        this.height = height;
    }

    // 绘制三角形
    public void Triangle() {
        for (int i = 1; i <= height; i++) {
            for (int m = 1; m <= height - i; m++) {
                System.out.print(" ");
            }
            for (int n = 1; n <= 2 * i - 1; n++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    // 绘制矩形
    public void Rectangle(int width) {
        for (int i = 1; i <= height; i++) {
            for (int m = 1; m <= width; m++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    // 绘制正方形
    public void Square() {
        Rectangle(height);
    }

    // 绘制平行四边形
    public void Parallelogram(int width) {
        for (int i = 1; i <= height; i++) {
            for (int m = 1; m <= height - i; m++) {
                System.out.print(" ");
            }
            for (int n = 1; n <= width; n++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        // 创建一个Draw类对象，高度设为6
        Draw draw = new Draw(6);

        // 绘制三角形
        System.out.println("三角形:");
        draw.Triangle();
        System.out.println();

        // 绘制矩形
        System.out.println("矩形:");
        draw.Rectangle(5);
        System.out.println();

        // 绘制正方形
        System.out.println("正方形:");
        draw.Square();
        System.out.println();

        // 绘制平行四边形5
        System.out.println("平行四边形:");
        draw.Parallelogram(5);
    }
}